package com.atguigu.srb.oss.controller;

import com.atguigu.srb.common.result.R;
import com.atguigu.srb.oss.service.OssService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/oss/file")
@Api(tags = "存储管理")
@Slf4j
@CrossOrigin
public class ApiOssFileController {
    @Autowired
    OssService ossService;

    @PostMapping("uploadImage")
    public R uploadImage(@RequestParam("file")MultipartFile multipartFile,String module){
        String url = ossService.uploadImage(multipartFile,module);
        return R.OK().data("url",url);
    }

    @DeleteMapping("removeImage")
    private R removeImage(String url){
        ossService.removeImage(url);
        return R.OK();
    }
}
